package com.fuyin.schedule;

import com.fuyin.dao.GpDao;
import com.fuyin.service.api.PythonApiService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author yuanxilan (yuanxilan@keep.com)
 * @Description 股票类定时任务
 * @date 2021年11月30日 9:08 下午
 * @since
 */
@Slf4j
@Component
public class GpHandler {

    @Autowired
    private GpDao gpDao;

    @Autowired
    private PythonApiService pythonApiService;

    /**
     * 定时更新股票信息
     *
     * @param
     * @return {@link ReturnT<String>}
     * @author 袁希岚
     * @date 2021/11/30 <br>
     * @since
     */
    @XxlJob("updateGpDetails")
    public ReturnT<String> execute(String param) throws Exception {
        log.info("{} updateGpDetails Begin", new Date());
        List<String> agjcs = gpDao.getCompanyAgjcs();
        for (String agjc : agjcs) {
            try {
                pythonApiService.saveData(agjc);
                log.info("{} 已爬取完毕", agjc);
            } catch (Exception e) {
                XxlJobHelper.log(e);
                log.warn("{} 爬取失败", agjc);
            }
        }
        log.info("{} updateGpDetails End", new Date());
        return ReturnT.SUCCESS;
    }
}
